<?php
	include("../connect/connect_dsccmis.php");
	$sql="call dscc.createTempOrphan;";
	$rs=mysql_query($sql);
	$sql = "call dscc.createTempEventCase;";
	$rs=mysql_query($sql);
	
	//แปลงประเภทเหตุการณ์จาก evntypid จาก evnrelevntyp ไปเป็น mis_evntypid โดยใช้ตาราง convert_evntype
	$sql = "drop table if exists mis_numvictim_losbodyOrphan;";
	$rs=mysql_query($sql);
    $sql="create table mis_numvictim_losbodyOrphan as 
	select t.facdscc,t.faevndte,t.reg,t.sex,left(t.faevnplcidgen,2) as prov,right(left(t.faevnplcidgen,4),2) as amp,perid from dscc.temporphan t 
	where (summlosbody<>'เสียชีวิต' or summlosbody is null)and (t.preid='07' or t.preid='08' or (t.age<=25 and t.age<>0))and fasummlosbody='เสียชีวิต' and faperlostypid not in ('22','41')
	";
	
	$rs=mysql_query($sql);
	//mysql_free_result($rs);
	//mysql_close($c);
	if($rs){
	echo "<br>complete create mis_numvictim_losbodyOrphan on dsccmis";
	}else{
		echo"can not process.";
	}
?>